package com.ctgu.j08.controller;

import com.ctgu.j08.service.BuyListService;
import com.ctgu.j08.vo.BuyList;
import com.ctgu.j08.vo.Device;
import com.ctgu.j08.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @version 1.0
 * @author: Saiya Wang
 * @date: 2021/6/2 9:19
 */
@Controller
@RequestMapping("/buy")
public class BuyListController {
    @Autowired
    private BuyListService buyListService;

    @PostMapping("/add")
    @ApiOperation("添加采购信息")
    @ResponseBody
    public Result addBuyList(@RequestBody BuyList buyList){
        System.out.println("添加的设备"+buyList);
        return buyListService.addBuyList(buyList);
    }

//    @PutMapping("/edit")
//    @ApiOperation("更新采购状态")
//    public Result editBuyList(@RequestBody BuyList buyList)
//    {
//        return buyListService.editBuyList(buyList);
//    }

    @PutMapping("/edit/{buyId}")
    @ApiOperation("更新采购状态")
    @ResponseBody
    public Result editBuyList(@PathVariable("buyId") Integer buyId)
    {
        System.out.println("修改的Id"+buyId);
        return buyListService.editBuyList(buyId);
    }

    @GetMapping("/getAll")
    @ApiOperation("获取全部采购信息")
    @ResponseBody
    public Result getAllBuyList()
    {
        return buyListService.getAllBuyList();
    }

    @GetMapping("/search/{deName}")
    @ApiOperation("查询采购信息")
    @ResponseBody
    public Result searchBuyInfo(@PathVariable("deName") String deName)
    {
        System.out.println("查询Controller");
        return buyListService.searchBuyListByName(deName);
    }
}
